package com.itheima.consumer.config;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FanoutConfig {

    /**
     * 声明交换机
     * @return Fanout类型交换机
     */
    @Bean
    public FanoutExchange fanoutExchange() {
//        方式1 和方式2
//        ExchangeBuilder.fanoutExchange("hmall.fanout1").build();
        return new FanoutExchange("hmall.fanout1");
    }
    /**
     * 第1个队列
     */
    @Bean
    public Queue fanoutQueue3(){
        // 方式1 和方式2
//        QueueBuilder.durable("fanout.queue3");
        return new Queue("fanout.queue3");
    }
    /**
     * 绑定队列和交换机
     */
    @Bean
    public Binding bindingQueue3(Queue fanoutQueue3, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue3).to(fanoutExchange);
    }

    @Bean
    public Queue fanoutQueue4(){
        return new Queue("fanout.queue4");
    }
    /**
     * 绑定队列和交换机
     */
    @Bean
    public Binding bindingQueue4(){
        // fanoutQueue4() bean 有这创建没有直接从spring中取
        return BindingBuilder.bind(fanoutQueue4()).to(fanoutExchange());
    }
}
